#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
class Group
{
    public:
        virtual int add(int x,int y)=0;
        virtual int sub(int x,int y)=0;
};
class GroupA:public Group
{
    public:
        int add(int x,int y)
        {
            return x+y;
        }
        int sub(int x,int y)
        {
            return x-y;
        }
};
class GroupB:public Group
{
    public:
        int sub(int x,int y)
        {
            string a=to_string(x);
            string b=to_string(y);
            reverse(a.begin(),a.end());
            reverse(b.begin(),b.end());
            int len=min(a.size(),b.size());
            string ans="";
            int i=0;
            for(i=0;i<len;++i)
            {
                if(a[i]<b[i])
                {
                    char tmp=('9'+1)-b[i]+a[i];
                    ans=ans+tmp;
                }
                else if(a[i]==b[i])
                {
                    ans=ans+'0';
                }
                else if(a[i]>b[i])
                {                    
                    char tmp=a[i]-b[i]+'0';
                    ans=ans+tmp;
                }
            }
            while(i<a.size())
            {
                ans+=a[i];
                ++i;
            }
            while(i<b.size())
            {
                ans+=b[i];
                ++i;
            }
            reverse(ans.begin(),ans.end());
            return atoi(ans.c_str());
        }
        int add(int x,int y)
        {
            return x+y;
        }
};
class GroupC:public Group
{
    public:
        int add(int x,int y)
        {
            string a=to_string(x);
            string b=to_string(y);
            reverse(a.begin(),a.end());
            reverse(b.begin(),b.end());
            string ans="";
            int len=min(a.size(),b.size());
            int i=0;
            for(i=0;i<len;++i)
            {
                char tmp=a[i]+b[i];
                if(tmp>'9')
                {
                    tmp-=('9'+1);
                }
                ans=ans+tmp;
            }
            while(i<a.size())
            {
                ans+=a[i];
                ++i;
            }
            while(i<b.size())
            {
                ans+=b[i];
                ++i;
            }
            reverse(ans.begin(),ans.end());
            return atoi(ans.c_str());
        }
        int sub(int x,int y)
        {
            string a=to_string(x);
            string b=to_string(y);
            reverse(a.begin(),a.end());
            reverse(b.begin(),b.end());
            int len=min(a.size(),b.size());
            string ans="";
            int i=0;
            for(i=0;i<len;++i)
            {
                if(a[i]<b[i])
                {
                    char tmp=('9'+1)-b[i]+a[i];
                    ans=ans+tmp;
                }
                else if(a[i]==b[i])
                {
                    ans=ans+'0';
                }
                else if(a[i]>b[i])
                {                    
                    char tmp=a[i]-b[i]+'0';
                    ans=ans+tmp;
                }
            }
            while(i<a.size())
            {
                ans+=a[i];
                ++i;
            }
            while(i<b.size())
            {
                ans+=b[i];
                ++i;
            }
            reverse(ans.begin(),ans.end());
            return atoi(ans.c_str());
        }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int tag,num1,num2,ans;
        char op;
        Group* p;
        cin>>tag>>num1>>op>>num2;
        if(tag==1)
        {
            p=new GroupA();
            if(op=='+')
            {
                cout<<p->add(num1,num2)<<endl;
            }
            else
            {
                cout<<p->sub(num1,num2)<<endl;
            }
            delete p;
        }
        else if(tag==2)
        {
            p=new GroupB();
            if(op=='+')
            {
                cout<<p->add(num1,num2)<<endl;
            }
            else
            {
                cout<<p->sub(num1,num2)<<endl;
            }
            delete p;
        }
        else
        {
            p=new GroupC();
            if(op=='+')
            {
                cout<<p->add(num1,num2)<<endl;
            }
            else
            {
                cout<<p->sub(num1,num2)<<endl;
            }
            delete p;
        }
    }
}